<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/yzr_style.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>验收药品</title>
</head>
<body>

<script type="text/javascript">
	$(function(){
		
		//获取当前登录用户的id
		var  checkYsr_staffId = $("#tontyiStaffId").html();
		
		var dingdanId = undefined;
		//打开面板
		$("#yzr-openpanel-btn").linkbutton({
			onClick: function(){
				$("#yzr-selectOrder-panel").window("open");
				$("#tb-purchorder-selOrder").datagrid({
		    		url: 'queryAllOrderByNoCheck_yzr', 
		    		method: 'get'
		    	});
				$("#yzr-checkMed-staff").combogrid("setValue",checkYsr_staffId);
			}
		});
		
		//选择订单
		$("#yzr-ok-btn").linkbutton({onClick: function(){
			var rows = $("#tb-purchorder-selOrder").datagrid("getSelections");
			if(rows.length == 1){
				var dingdanId = rows[0].purchOrderId;
				var yanshouState = rows[0].purchYanshouState;
				if(yanshouState == '已验收'){
					$.messager.alert("提示", "该订单已验收，不能重复验收！");
				}else{
					$("#yzr-selectOrder-panel").window("close");
					$("#yzr-order-input").textbox("setValue",dingdanId);
					var dingdanId = undefined;
				}				
			}else{
				$.messager.alert("提示", "您还没有选择记录！");
			}
		}});
		
		//模糊查询
		$('#yzr-selOrder-search').searchbox({
		    searcher:function(value,name){
		    	if(value == ''){
		    		$.messager.alert("提示", "请输入查询条件！");
		    	}else{
		    		$("#tb-purchorder-selOrder").datagrid({	    		
			    		url:'queryByIf',
			    		method: 'post', 
			    		queryParams: {
			    			value: value,
			    			name: name
			    	}});
			    	$('#yzr-selOrder-search').searchbox('setValue', '');
		    	}	    			    	
		    }		    
		}); 
		
		//显示全部
		$("#yzr-selOrder-reload").linkbutton({onClick:function(){
			$("#tb-purchorder-selOrder").datagrid({
	    		url: 'queryAllOrderByNoCheck_yzr', 
	    		method: 'get'
	    	});
		}});
		
		//根据日期段查询
		$("#yzr-ok-search").linkbutton({onClick:function(){
			
			var start = $("#yzr-selOrder-startDate").datebox("getValue");
			var end = $("#yzr-selOrder-endDate").datebox("getValue");
			
			if(start == '' || end == ''){
				$.messager.alert("提示", "请选择日期！");
			}else{
				$("#tb-purchorder-selOrder").datagrid({
		    		url: 'queryByJiaoHuoDate', 
		    		method: 'post',
		    		queryParams: {
		    			startDate: start,
		    			endDate: end
		    	}});
				$('#yzr-selOrder-startDate').datebox('setValue', '');
				$('#yzr-selOrder-endDate').datebox('setValue', '');
			}			
		}});
		
		//根据采购id查找出采购详情
		$("#yzr-order-input").textbox({onChange: function(newValue, oldValue){
				$.messager.alert("提示", "请勾选合格的药品！");
				 $("#yzr-checkMed-dg").datagrid({
					url:'queryOrderByOrderId',
					width: '100%',
					queryParams:{
						page:1, 
		    			rows:100,
		    			orderId: newValue
					}
				});
			}
		});
		
		// 提交数据
		$("#yzr-checkMed-submit").linkbutton({onClick: function(){		
			//返回所有选中的行
			var rows = $("#yzr-checkMed-dg").datagrid("getSelections");
			var arr = [];
			for(var i = 0; i < rows.length; i ++){
				arr.push(rows[i].purchOrderDetId);
				//$.messager.alert("提示", rows[i].purchOrderDetId);
			}
			
			
			var orderId = $("#yzr-order-input").textbox("getValue");
			var staffId = $("#yzr-checkMed-staff").combogrid("getValue");
			var checkDate = $("#yzr-checkMed-date").datebox("getValue");
			
			
			
			/* $.messager.alert("提示", orderId);
			$.messager.alert("提示", staffId);
			$.messager.alert("提示", checkDate); */
			
			$('#yzr_checkMed_form').form('submit', {
				url: 'submitCheckMed_yzr',
				queryParams:{
					list:arr,
					orderId:orderId,
					staffId: staffId,
					checkDate:checkDate
				},
			    onSubmit: function(){
			    	return $(this).form("validate");
			    },
			    success:function(data){
			    	var json = eval("(" + data + ")");
					$.messager.alert("提示", json.reason);
					$(this).form("clear");
					$('#yzr-checkMed-dg').datagrid('loadData', { total: 0, rows: [] }); 
					/* $('#yzr-supp-window').window('close');
					$("#tb-supplier").datagrid("reload");
					$(this).form("clear"); */
			    }
			});
		}});
		
	});
	
</script>
	
	<!-- 验收单数据 -->
	<form id="yzr_checkMed_form" method="post" style="padding:20px;background:#ECF3FF;">
<!-- 		<div style="background:#ECF3FF;"> -->
		<input id="yzr-order-input" class="easyui-textbox" data-options="required:true,width: '30%',labelAlign:'right',label:'采购单'"/>
		<a id="yzr-openpanel-btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查找</a>
		<select class="easyui-combogrid" id="yzr-checkMed-staff"
			data-options="
				label: '验收人',
				labelAlign:'right',
				required:true,
				width: '30%',
				panelWidth: '290',
				panelHeight: 'auto',
				url: 'queryAllStaff',
				pagination: true,
				pageSize: 8,
				pageList: [8, 16, 24, 32],
				idField: 'staffNo',
				textField: 'staffName',
				columns: [[
					{field:'staffName',title:'姓名',width:100},
					{field:'departmentName',title:'部门',width:100},
					{field:'postName',title:'职务',width:85}
				]]
		"></select>
		<input class="easyui-datebox" id="yzr-checkMed-date" data-options="width:'30%',required:true,labelAlign:'right',label:'验收日期'">				
		</form>
		<!-- 订单明细 -->
		<div style="margin: 5px;">
			<div id="yzr-checkMed-tabs" class="easyui-tabs" style="width:98%; margin-top:20px;margin-left:10px;" 
				data-options="plain:true,narrow:true">
				
				<div title="采购明细" style="padding:10px;">
					<table id="yzr-checkMed-dg" class="easyui-datagrid" 
							data-options="
								iconCls: 'icon-edit',									
								width: '98%'
								">
							<thead>
								<tr>	
									<th data-options="field:'purchOrderDetId',width:'18%',align:'center'">采购订单明细编号</th>			
									<th data-options="field:'orderDetMedName',width:'18%',align:'center'">药品名称</th>
									<th data-options="field:'orderDetGuige',width:'10%',align:'center'">规格</th>
									<th data-options="field:'orderDetMedUnit',width:'10%',align:'center'">单位</th>
									<th data-options="field:'orderDetPrice',width:'10%',align:'center'">单价</th>
									<th data-options="field:'orderDetNumber',width:'8%',align:'center'">数量</th>
									<th data-options="field:'orderDetMoney',width:'10%',align:'center'">金额</th>
									<th data-options="field:'supName',width:'13%',align:'center'">供应商</th>
									<th data-options="field:'XXX',width:'2%',idField:'purchOrderDetId',checkbox:true">是否合格</th>
								</tr>
							</thead>
					 </table>
				</div>							
			</div>						
		</div>
	
		<!-- 确认按钮 -->
		<a id="yzr-checkMed-submit" class="easyui-linkbutton" style="margin-top:10px;margin-left:10px;algin:right;" data-options="iconCls:'icon-ok'">提交</a>
	
	
	
	
	<!-- 选择订单窗口 -->
	<div id="yzr-selectOrder-panel" class="easyui-window" title="选择采购订单" style="width:900px;height:350px;" data-options="closable:true,closed:true,collapsible:false,minimizable:false,maximizable:false">
		<table id="tb-purchorder-selOrder" class="easyui-datagrid" 
			data-options="
				url:'queryAllOrder',				
				fit:true,
				pagination: true,
				pageSize: 8,
				pageList: [8, 16, 24, 32],
				rownumbers: false,
				toolbar: '#yzr-toolbar-selOrder',
				border:false,
				singleSelect:true
				">
			<thead>
				<tr>	
					<th data-options="field:'purchOrderId',width:'10%',checkbox:true,align:'center'">订单编号</th>				
				<th data-options="field:'purchPurchId',width:'17%',align:'center'">计划单号</th>
				<th data-options="field:'staffName',width:'10%',align:'center'">采购人</th>											
				<th data-options="field:'purchOrderDate',width:'13%',
									formatter:function(value){
					                          var date = new Date(value);  
					                          return date.toLocaleDateString();},align:'center'"
				>订货日期</th>				
				<th data-options="field:'purchJiaohuoDate',width:'13%',
									formatter:function(value){
					                          var date = new Date(value);  
					                          return date.toLocaleDateString();},align:'center'"
				>交货日期</th>
				<!-- <th data-options="field:'purchJiaohuoAddress',width:'12%',align:'center'">交货地点</th> -->
				<th data-options="field:'purchOrderNumber',width:'11%',align:'center'">订货项数</th>	
				<th data-options="field:'purchOrderMoney',width:'11%',align:'center'">订单金额</th>
				<th data-options="field:'purchYanshouState',width:'11%',
									styler:function(value,row,index){ 
											if(row.purchYanshouState == '未验收'){
												return 'color:red;';
											}},
					                           align:'center'">验收状态</th>
					                          
				<th data-options="field:'purchInstockState',width:'11%',align:'center'">是否入库</th>					
				</tr>
			</thead>
		</table>				    
	    
	    <!-- 工具栏 -->
	    <div id="yzr-toolbar-selOrder">
	    	<input id="yzr-selOrder-search" class="easyui-searchbox" data-options="menu: '#yzr-serch', width: 250, prompt: '请输入关键字'"/>    	
	    	<input id="yzr-selOrder-startDate" class="easyui-datebox" data-options="label:'交货日期',labelAlign:'right', width: 200" /> -
	    	<input id="yzr-selOrder-endDate" class="easyui-datebox" data-options="width: 110"/>
	    	<a id="yzr-ok-search" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
	    	<a id="yzr-ok-btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="margin-left:110px;">确定</a>
	    	<a id="yzr-selOrder-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">刷新</a>
	    </div>
	    	    
	    <!-- 搜索框 -->
	    <div id="yzr-serch" style="width:120px">
	    	<div data-options="name:'orderId'">订单编号</div>
		    <div data-options="name:'name'">采购人</div>
		    <div data-options="name:'checkState'">验收状态</div>
		    <div data-options="name:'rukuState'">是否入库</div>
		</div>		
	</div>	
	
	
	
</body>
</html>